#1
# -*- coding:utf-8 -*-
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:
    def Print(self, pRoot):
        # write code here
        if not pRoot:
            return []
        cur = [pRoot]
        nextLayer = []
        res = []
        count = 1
        while cur:
            for i in cur:
                if i.left: nextLayer.append(i.left)
                if i.right: nextLayer.append(i.right)
            if count % 2:
                res.append([i.val for i in cur])
                count += 1
            else:
                res.append([i.val for i in cur[::-1]])
                count += 1
            cur = nextLayer
            nextLayer = []
        return res
